﻿/////////////////////////////////////////////////////////////////////
//
//	Map_FVG C# Class Library.
//
//	MyControlLinea
//	
//
//	autore: Gustavo Mainardi 
//	versione: 1.0
//	data: 01/12/2015
//
//
//	Cronologia delle versioni:
//
//	Versione 1.0 01/12/2015
//		versione originale
//
//////////////////////////////////////////////////////////////////////////
using System;
using System.Drawing;
using System.Windows.Forms;

namespace Map_Fvg
{
    public partial class MyControlLinea : UserControl, IDragDropEnabled
    {

        private Color colorTextColor;

        public MyControlLinea()
        {
            InitializeComponent();
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            if (!this.IsDragging)
            {
 //               if (ViewQ.LineaSelect_flag == 1)
                if (ViewQ.Select_flag == (int)ViewQ.flagSelez.linea)
                {
                    Graphics dc = e.Graphics;

                    Color icolor = Color.Red;
                    SolidBrush iBrush = new SolidBrush(icolor);

                    Pen redPen = new Pen(Color.Red, 1);
                    Point Pnt = new Point(0, 0);

                    Rectangle pntR = new Rectangle(0, 0, 5, 5);

                    dc.DrawRectangle(redPen, pntR);

                }
            }
        }

        public Color colore
        {
            get
            {
                return colorTextColor;
            }
            set
            {
                if (value != null) colorTextColor = value;
            }
        }


        bool m_IsDragging = false;

        /// <summary>
        /// Required designer variable.
        /// </summary>
        //	private System.ComponentModel.Container components = null;

        /// <summary>
        /// Gets / Sets if the control is being dragged
        /// </summary>
        public bool IsDragging
        {
            get { return m_IsDragging; }
            set { m_IsDragging = value; }
        }

        /// <summary>
        /// Unused but in the interface
        /// </summary>
        public void StoreLocation()
        {


        }

        public void DropComplete(bool _successfull)
        {

        }

        public void completedDrag(int X, int Y)
        {
            Point Hit = new Point();
            Point Hit1 = new Point();

            double angleRad = -ViewQ.alpha * Math.PI / 180.0D;

            Hit1.X = (int)((double)X * Math.Cos(angleRad) - (double)Y * Math.Sin(angleRad)) - ViewQ.Xoff;
            Hit1.Y = (int)((double)X * Math.Sin(angleRad) + (double)Y * Math.Cos(angleRad)) - ViewQ.Yoff;

            Hit.X = (int)(Hit1.X / ViewQ.scalaX) + ViewQ.Xmin;
            Hit.Y = (int)(Hit1.Y / ViewQ.scalaY) + ViewQ.Ymin;

            int ipnt = ViewQ.vectShapes[ViewQ.selected_linea].pntpL + ViewQ.selected_point;

            ViewQ.PL[ipnt].X = Hit.X;
            ViewQ.PL[ipnt].Y = Hit.Y;
            ViewQ.vectShapes[ViewQ.selected_linea].modifica = 1;
            Save.modificaLinea = 1;
        }


    }
}
